<template>
  <div>
    <!-- 学生实验提交 -->
     <el-card class="box-card">
      <el-form :inline="true" class="demo-form-inline">
       
        <el-form-item label="实验名">
          <el-input
            v-model="experiment"
            placeholder="请输入实验名"
          ></el-input>
        </el-form-item>
        <el-form-item label="实验日期">
           <el-date-picker
            v-model="date"
              type="date"
              value-format="yyyy-MM-dd" 
              placeholder="选择日期">
            </el-date-picker>
        </el-form-item>

        <el-form-item label="实验时间">
            <el-select v-model="time" placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="load(1)">查询</el-button>
          <el-button type="info" @click="reset()">清空</el-button>
        </el-form-item>
      </el-form>
      </el-card>

    <el-table
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%"
    >
      <el-table-column prop="id" label="编号"> </el-table-column>
      <el-table-column prop="lesson" label="班级"> </el-table-column>
      <el-table-column prop="susername" label="学生学号"> </el-table-column>
      <el-table-column prop="experiment" label="实验名"></el-table-column>
      <el-table-column prop="description" label="实验描述"></el-table-column>
      <el-table-column prop="local" label="实验室位置"> </el-table-column>
      <el-table-column prop="date" label="实验日期"> </el-table-column>
      <el-table-column prop="time" label="时间"> </el-table-column>
      <el-table-column prop="file" label="文件地址"> </el-table-column>
       <el-table-column prop="grade" label="成绩"> </el-table-column>
    

     <el-table-column align="center" label="操作">
        <template slot-scope="scope">
          <el-button type="primary" size="small" @click="update(scope.row)"
            >编辑</el-button
          >
        </template>
      </el-table-column>
      </el-table>  

 <el-row>
      <div class="block" style="margin:10px 0">
    <el-pagination
      @current-change="handleCurrentChange"
      :current-page="page"
      :page-sizes="[100, 200, 300, 400]"
      :page-size="pageSize"
      layout="total, prev, pager, next"
      :total="total">
    </el-pagination>
  </div>
    </el-row>
    
     
      <el-dialog title="提交实验报告" :visible.sync="formVisible"  width="75%">
        <el-form :model="form" label-width="80px" style="padding-right : 20px">
            <el-form-item label="学生学号" prop="susername">
            <el-input v-model="form.susername" disabled></el-input>
            </el-form-item>
            <el-form-item label="实验名" prop="experiment">
            <el-input v-model="form.experiment" disabled></el-input>
            </el-form-item>

            <el-form-item label="实验描述" prop="description">
            <el-input type="textarea"
              autosize  maxlength="100"
              show-word-limit v-model="form.description" disabled>></el-input>
            </el-form-item>

            <el-form-item label="实验室位置" prop="local">
            <el-input v-model="form.local" disabled></el-input>
            </el-form-item>

            <el-form-item label="实验日期">
           <el-date-picker
            v-model="form.date"
              type="date"
              value-format="yyyy-MM-dd" 
              disabled
              placeholder="选择日期">
            </el-date-picker>
        </el-form-item>

        <el-form-item label="实验时间" prop="time">
            <el-input v-model="form.time" disabled></el-input>
            </el-form-item>

        <el-form-item label="实验计划文件">
            <el-upload
              class="upload-demo"
              action="http://localhost:8080/files/"
              :file-list="fileList"
              :on-success="handFileSuccess"
            >
              <el-button size="small" type="primary">点击上传</el-button>
              <div slot="tip" class="el-upload__tip">上传实验计划文件</div>
            </el-upload>
        </el-form-item>

            <el-form-item>
            <el-button type="primary" @click="save()">提交</el-button>
            <el-button @click="formVisible = false">取消</el-button>
            </el-form-item>
      </el-form>
    </el-dialog>



  </div>
</template>

<script>
export default {
    name:'SHomework',
    data () {
        return {
          user: JSON.parse(localStorage.getItem("honey-user") || "{}"),
          experiment : '',
          date : '',
          time :'',
          tableData:[], // 所有数据
          page : 1, // 当前的页码
          pageSize : 5, // 每页显示的个数
          total : 0,
          formVisible : false,
          options: [{
          value: '08:20-09:55',
          label: '08:20-09:55'
        }, {
          value: '10:10-11:45',
          label: '10:10-11:45'
        }, {
          value: '10:10-12:30',
          label: '10:10-12:30'
        }, {
          value: '13:20-14:55',
          label: '13:20-14:55'
        }, {
          value: '15:10-16:45',
          label: '15:10-16:45'
        },{
          value: '15:10-17:30',
          label: '15:10-17:30'
        },{
          value: '18:15-19:50',
          label: '18:15-19:50'
        },{
          value: '18:15-20:35',
          label: '18:15-20:35'
        }],
        fileList : [],
        form : {}
            
        }
    },
    created () {
        this.load();
    },
    methods: {
      save(){
      this.$request.put("/homeworks",this.form).then((res) => {
        if(res.code === 1){
                this.$message({
                //message: '登陆成功',
                message:res.msg,
                type: 'success'
            });
            this.load(1);
            this.formVisible = false;
            }else{
                 this.$message({
                //message: '登陆失败',
                message: res.msg,
                type: 'warning'
            });
            }
      }).catch((err) => {
        console.log(err);
      });
    },
      update(row){
        this.form = JSON.parse(JSON.stringify(row)); // 给student对象赋值
        this.formVisible = true; // 显示弹窗
      },
       load(page){ // 分页查询
        if (page) {
            this.page = page;
        }
        this.$request.get('/homeworks',{
            params : {
                page : this.page,
                pageSize : this.pageSize,
                susername:this.user.username,
                experiment:  this.experiment,
                date : this.date,
                time : this.time

            }
        }).then((res) => {
            this.total = res.data.total;
            this.tableData = res.data.rows;
        }).catch((err) => {
            console.log(err);
        });
    },
    handleCurrentChange(page){
      //  this.page = page;
        this.load(page);
    },
    reset(){
        this.experiment = '';
        this.date = '';
        this.time = '',
        this.load(1);
    },
    handFileSuccess(response, file,fileList){
      this.form.file = response.data;
      console.log(response,file,fileList);
    }
        
    }
}

</script>

<style>

</style>